package com.alibaba.citrus.ots.b2b.trade.order.functions.utils;

import com.epoch.app.otsb2btradecenter.dto.request.OrderLineSaveInnerRequest;
import com.epoch.app.otsb2btradecenter.sdo.OrderLineSDO;
import com.epoch.app.otsb2btradecenter.sdo.ScItemSDO;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

@Component
public class SaveOrderLineConverter {

    public static OrderLineSDO converterOrderLineSDO(OrderLineSaveInnerRequest request) {
        OrderLineSDO orderLineSDO = new OrderLineSDO();

        ScItemSDO scItemSDO = new ScItemSDO();
        scItemSDO.setScItemId(request.getGoodsId());
        scItemSDO.setScItemTitle(request.getGoodsName());
        if (StringUtils.isNotBlank(request.getQuantity())) {
            scItemSDO.setQuantity(Integer.parseInt(request.getQuantity()));
        }

        orderLineSDO.setScItemSDO(scItemSDO);
        scItemSDO.setSaleUnit(request.getSaleUnit());
        orderLineSDO.setRemark(request.getRemark());
        return orderLineSDO;
    }
}
